package com.wyh.service.serviceImpl.feemanagementserviceimpl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wyh.domain.po.feemanagementpo.Paymentmethod;
import com.wyh.mapper.feemanagementmapper.PaymentmethodMapper;
import com.wyh.service.feemanagementservice.PaymentmethodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;


@Service
public class PaymentmethodServiceImpl extends ServiceImpl<PaymentmethodMapper, Paymentmethod> implements PaymentmethodService {

    private static final List<String> ALLOWED_PAYMENT_METHODS = Arrays.asList("现金", "支票", "微信支付");

    @Autowired
    private PaymentmethodMapper paymentmethodMapper;
    @Override
    public int insert(Paymentmethod paymentmethod) {
        validatePaymentMethod(paymentmethod.getName());
        return paymentmethodMapper.insert(paymentmethod);
    }

    @Override
    public Paymentmethod findByName(String name) {
        return paymentmethodMapper.findByName(name);
    }

    private void validatePaymentMethod(String name) {
        String normalizedName = name.toLowerCase().trim();
        System.out.println("Validating payment method: " + name + " (normalized: " + normalizedName + ")");
        if (!ALLOWED_PAYMENT_METHODS.contains(normalizedName)) {
            throw new IllegalArgumentException("不支持的付款方式: " + name);
        }
    }
}
